package com.huanong.controller.impl;
/*
 *@Author:anran
 *@Date:2020/12/9
 *@Version 1.0
 */

import com.huanong.common.grace.result.GraceJSONResult;
import com.huanong.controller.ContactControllerApi;
import com.huanong.pojo.ConTact;
import com.huanong.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ContactController implements ContactControllerApi {

    @Autowired
    private ContactService contactService;

    @Override
    public GraceJSONResult queryContact() {
        List<ConTact> list=contactService.query();
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult queryContactById(Integer CtId) {
        ConTact conTact=contactService.queryById(CtId);
        return GraceJSONResult.ok(conTact);
    }

    @Override
    public GraceJSONResult addContact(ConTact conTact) {
        int flag=contactService.add(conTact);
        if (flag==1){
            return GraceJSONResult.ok("添加联系记录成功");
        }else {
            return GraceJSONResult.errorMsg("添加联系记录失败");
        }
    }

    @Override
    public GraceJSONResult deleteContact(Integer CtId) {
        int flag=contactService.delete(CtId);
        if (flag!=0){
            return GraceJSONResult.ok("删除联系记录成功");
        }else {
            return GraceJSONResult.errorMsg("删除联系记录失败");
        }
    }

    @Override
    public GraceJSONResult updateContact(ConTact conTact) {
        int flag=contactService.update(conTact);
        if (flag!=0){
            return GraceJSONResult.ok("更新联系记录成功");
        }else {
            return GraceJSONResult.errorMsg("更新联系记录失败");
        }
    }
}
